﻿
package com.fdl.action.support;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.fdl.dao.base.impl.Page;

/**
 * 分页的通用Action
 * @project: hb-intra
 * @Date:2010-8-6
 * @version  1.0
 * @Company: 33e9
 * @author jing.qiu
 */
public class SupportAction {
	
	/**
	 * 每页显示记录数
	 */
	protected int pageSize = 10;
	
	/**
	 * 用于保存当前页码
	 */
	protected int pageno=0;
	
	/**
	 * 总的页数
	 */
	protected int totalPageCount;
	
	/**
	 * 总的记录数
	 */
	protected int totalCount;
	
	/**
	 * 保存操作消息的Map对象
	 */
	protected Map<String, String> messageMap=new HashMap<String, String>();
	
	/**
	 * 取分页的总记录数-1和页面显示数据的模,判断当前应该显示的页数是否需要减少1
	 * @param totalCount
	 * @param pageSize
	 * @param pageNoPara
	 * @return
	 */
	protected int getPageNoParaByLastCount(int totalCount,int pageSize,int pageNoPara){
		if(totalCount<=0||pageSize<=0){
			return pageNoPara;
		}
		if ((totalCount - 1) % pageSize == 0) {
			return pageNoPara-1;
		}else{
			return pageNoPara;
		}
	}
	
	/**
	 * 调用分页标签时取得当前页面的PageNo
	 * @param request
	 * @param totalPageCount
	 * @return 当前页码
	 */
	protected int getPageNoPara(HttpServletRequest request,int totalPageCount,int pageNoPara){
		int pageno=0;
		try {
				pageno=Integer.parseInt(request.getParameter("pageno"));
				if(pageno>totalPageCount){
					pageno=totalPageCount;
				}
				if(pageno<=0){
					pageno=1;
				}
		} catch (Exception e) {
			if(pageNoPara>0)
				pageno=pageNoPara;
			else
				pageno=1;
		}
		return pageno;
	}
	
	/**
	 * 把记录数带到页面
	 * 
	 * @param page
	 */
	protected void wrapPageInfo(Page page) {
		totalPageCount = page.getTotalPageCount();
		totalCount = page.getTotalSize();
	}
}

